﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Model;
using System.Collections.ObjectModel;
using University.Workshop.DataAccess;
using System.Globalization;
using System.Windows.Forms;

namespace University.Workshop.Business
{
    public static class InvoiceManager
    {
        public static void ValidateInvoice(string id, string fullName, string ci, DateTime date, Collection<InvoiceDetail> detail)
        {
            if (detail == null)
            {
                throw new ArgumentNullException("detail");
            }
            if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(ci) || string.IsNullOrEmpty(fullName))
            {
                throw new ArgumentException("All input requiere");
            }

            try
            {
                Convert.ToInt32(ci, CultureInfo.InvariantCulture);
            }
            catch
            {
                throw new ArgumentException("the NIT/CI is invalid requiere only numbers");
            }
            InvoiceData data = new InvoiceData();
            data.Dispose();
            data.RegisterInvoice(new Invoice { Id = id, FullName = fullName,CI = ci, Date = date, Detail = detail });
        }
        public static Collection<InvoiceDetail> ConvertToCollection(ListView list)
        {
            if (list == null)
                throw new ArgumentNullException("list");
            Collection<InvoiceDetail> detail = new Collection<InvoiceDetail>();
            foreach (ListViewItem item in list.Items)
                detail.Add(new InvoiceDetail { Detail = item.SubItems[1].Text, Mount = item.SubItems[2].Text });

            return detail;
        }
    }
}
